//
//  ViewController.m
//  UITableView作业
//
//  Created by dllo on 16/7/25.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ViewController.h"
#import "FirstViewController.h"
#import "SecondViewController.h"
#import "DetailViewController.h"

@interface ViewController ()<UITableViewDataSource,UITableViewDelegate,SecondViewControllerDelegate>
@property (nonatomic,strong) NSMutableArray *studentArray;
@property (nonatomic,strong) UILabel *label;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
//    
//    NSString *path =;
//    NSLog(@"%@",path);
//    NSArray *array = [NSArray arrayWithContentsOfFile:path];
//    NSLog(@"%@",array);
//    self.view.backgroundColor = [UIColor redColor];
//    _nameArray = @[@"唐益梦", @"张合尉", @"高雅馨", @"符淋淋", @"孙遥", @"李毅然", @"于瀚", @"沙长健", @"卢思彤", @"徐昊", @"曹冠雄", @"陈丹明", @"罗浩", @"肖扬", @"王道林", @"宫雪", @"李成", @"冀永金", @"姜浩", @"罗鹏飞", @"李昊林", @"郭宝", @"马峰", @"刘坦奇", @"殷明静", @"邓凯", @"徐康", @"王鍠", @"韩旭", @"杨睿", @"张信宝", @"姜程程", @"包铭礼", @"杜江", @"苗钧豪"];
    NSString *path = [[NSBundle mainBundle] pathForResource:@"DLS160710" ofType:@"plist"];
//     NSLog(@"%@",path);
    NSArray *array = [NSArray arrayWithContentsOfFile:path];
    self.studentArray = [NSMutableArray arrayWithArray:array];
    
//    NSLog(@"%@",array);
//    self.navigationController.navigationBarHidden = YES;
//    ViewController *vc = [[ViewController alloc] init];
//    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
//    nav.navigationController.navigationBar.translucent = NO;
    self.title = @"点击";
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(160, 10, 50, 20);
    button.backgroundColor = [UIColor redColor];
    [button addTarget:self action:@selector(buttonClicked1) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    tableView.separatorColor = [UIColor redColor];
//    tableView.rowHeight = 100;
    tableView.delegate = self;
    tableView.dataSource = self;
    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    
    [self.view addSubview:tableView];
    
    
}




- (void)buttonClicked1
{
    SecondViewController *svc = [[SecondViewController alloc] init];
    svc.secondDelegate = self;
    [self.navigationController pushViewController:svc animated:YES];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
//   cell.textLabel.text = @"哈哈";
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(10, 10, 100, 40);
    button.backgroundColor = [UIColor blackColor];
    button.alpha = 0.2;
    [button setTitle:_studentArray[indexPath.row][@"name"] forState:UIControlStateNormal];
    [cell addSubview:button];
    [button addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventTouchUpInside];
    cell.detailTextLabel.text = @"特累次";
//    tableView.rowHeight = 50;
//    cell.contentView.backgroundColor = [UIColor redColor];
    
    
    return cell;
}

- (void)changeValue:(NSString *)news
{
    self.label.text = news;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    DetailViewController *detailVC = [[DetailViewController alloc] init];
    detailVC.student = _studentArray[indexPath.row];
    [self.navigationController pushViewController:detailVC animated:YES];
}



- (void)buttonClicked
{
    FirstViewController *fvc = [[FirstViewController alloc] init];
    [self.navigationController pushViewController:fvc animated:YES];
}

//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
//{
//    return 10;
//}
//


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _studentArray.count;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
